﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace ThreadSafeControls {
    partial class ThreadSafeListViewItem {
        public class ListViewSubItem {

            private readonly ListViewItem.ListViewSubItem _listViewSubItem;
            private readonly ThreadSafeListView _listView;

            internal ListViewSubItem(ListViewItem.ListViewSubItem listViewSubItem, ThreadSafeListView listView) {
                if (listViewSubItem == null)
                    throw new ArgumentNullException("listViewSubItem");
                else if (listView == null)
                    throw new ArgumentNullException("listView");

                _listViewSubItem = listViewSubItem;
                _listView = listView;
            }

            internal ListViewItem.ListViewSubItem SubItem {
                get { return _listViewSubItem; }
            }

            public Color BackColor {
                get { return _listView.ReturnAsync(c => _listViewSubItem.BackColor); }
                set { _listView.UpdateAsync(c => _listViewSubItem.BackColor = value); }
            }

            public Font Font {
                get { return _listView.ReturnAsync(c => _listViewSubItem.Font); }
                set { _listView.UpdateAsync(c => _listViewSubItem.Font = value); }
            }

            public Color ForeColor {
                get { return _listView.ReturnAsync(c => _listViewSubItem.ForeColor); }
                set { _listView.UpdateAsync(c => _listViewSubItem.ForeColor = value); }
            }

            public string Text {
                get { return _listView.ReturnAsync(c => _listViewSubItem.Text); }
                set { _listView.UpdateAsync(c => _listViewSubItem.Text = value); }
            }

            public void ResetStyle() {
                _listView.UpdateAsync(c => _listViewSubItem.ResetStyle());
            }
        }
    }
}
